package cn.wanho.handler;


import cn.wanho.rvo.ResultEnum;
import cn.wanho.rvo.ResultVO;
import cn.wanho.util.JsonUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description: 用户未登录时出现的情况
 * @author qzw
 */
@Component
public class UserAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResultVO result = ResultVO.failure(ResultEnum.USER_NOT_LOGIN.getResCode(), ResultEnum.USER_NOT_LOGIN.getResMsg());
        response.setContentType("text/json;charset=utf8");
        response.getWriter().write(JsonUtil.toJson(result));
    }
}
